<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('盘点列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <input name="manageDept" type="text" id="manageDept" style="display: none"/>
                <input name="deptId" type="text" id="deptId" style="display: none"/>
                <input name="inventoryId" type="text" id="inventoryId" style="display: none" th:value="${inventoryId}"/>
                <div class="select-list">
                    <ul>
                        <li>
                            <input type="text"  name="searchParam" placeholder="序号/编号/资产编码/名称/型号"/>
                        </li>
                        <li>
                            <input name="manageDeptName" onclick="selectDeptTree()" id="manageDeptName" type="text" placeholder="请选择管理部门">
                        </li>
                        <li>
                            <input name="deptName" onclick="selectDeptTreeUse()" id="deptName" type="text" placeholder="请选择使用部门">
                        </li>
                        <!--<li>-->
                            <!--<select name="status" class="form-control" th:with="type=${@dict.getType('status')}">-->
                                <!--<option value="">资产状态</option>-->
                                <!--<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>-->
                            <!--</select>-->
                        <!--</li>-->
                        <!--<li>-->
                        <!--<select name="inventoryStatus" class="form-control">-->
                        <!--<option value="">盘点情况</option>-->
                        <!--<option value="0">未盘点</option>-->
                        <!--<option value="1">已盘点</option>-->
                        <!--<option value="2">盘点一次以上</option>-->
                        <!--</select>-->
                        <!--</li>-->
                        <li>
                            <select name="useStatus" class="form-control" th:with="type=${@dict.getType('use_status')}">
                                <option value="">资产情况</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li class="select-time">
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="beginDate"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="endDate"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="inventory:inventoryAll:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var sUserAgent = navigator.userAgent.toLowerCase();
    var bIsIpad = sUserAgent.match(/ipad/i) == 'ipad';
    var bIsIphone = sUserAgent.match(/iphone os/i) == 'iphone os';
    var bIsMidp = sUserAgent.match(/midp/i) == 'midp';
    var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == 'rv:1.2.3.4';
    var bIsUc = sUserAgent.match(/ucweb/i) == 'web';
    var bIsCE = sUserAgent.match(/windows ce/i) == 'windows ce';
    var bIsWM = sUserAgent.match(/windows mobile/i) == 'windows mobile';
    var bIsAndroid = sUserAgent.match(/android/i) == 'android';
    var isNotPc;
    if(bIsIpad || bIsIphone || bIsMidp || bIsUc7 || bIsUc || bIsCE || bIsWM || bIsAndroid ){
        isNotPc = true
        $("#toolbar").hide();
    }else{
        isNotPc = false
    }
    var prefix = ctx + "inventory/inventory";

    $(function() {
        var options = {
            url: prefix + "/allByIdList",
            exportUrl: prefix + "/export",
            modalName: "盘点",
            height:520,
            columns: [
                {
                    field : 'assetId',
                    title : '资产序号',
                    sortable:true,
                },
                {
                    field : 'assetNo',
                    title : '卡片编号',
                    sortable:true,
                },
                {
                    field : 'assetCode',
                    title : '资产编码',
                    sortable:true,
                },
                {
                    field : 'assetName',
                    title : '资产名称'
                },
                {
                    title : '资产类别',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push($.table.selectDictLabel([[${@dict.getType('asset_type')}]], row.assetType));
                        return actions.join('');
                    },
                    visible:!isNotPc
                },
                {
                    field : 'specifications',
                    title : '规格'
                },
                {
                    field : 'assetModel',
                    title : '型号'
                },
                {
                    field : 'manageDeptName',
                    title : '管理部门',
                },
                {
                    field : 'useDeptName',
                    title : '使用部门'
                },
                {
                    field : 'address',
                    title : '使用地点'
                },
                {
                    title : '资产情况',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push($.table.selectDictLabel([[${@dict.getType('use_status')}]], row.useStatus));
                        return actions.join('');
                    },
                    visible:!isNotPc
                },
                {
                    title : '是否相符',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(row.agreementStatus==0){
                            actions.push("否");
                        }
                        if(row.agreementStatus==1){
                            actions.push("是");
                        }
                        return actions.join('');
                    }
                },
                {
                    align:'center',
                    title : '图片',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-info btn-xs" style="height: 30px;line-height: 25px" href="javascript:void(0)" onclick="showImg(\'' + row.assetId +","+true+ '\',\'' + row.imgCount + '\')">'+"&nbsp&nbsp"+row.imgCount+'&nbsp&nbsp</a>');
                        return actions.join('');
                    },
                },
                {
                    field : 'createByName',
                    title : '创建人',
                    visible:!isNotPc
                },
                {
                    field : 'createTime',
                    title : '创建时间',
                    sortable:true,
                    visible:!isNotPc
                },{
                    title : '数量',
                    formatter: function(value, row, index) {
                        var actions = [];
                        var amount=row.amount-row.lostScrapCount;
                        actions.push(amount);
                        return actions.join('');
                    },
                },
                {
                    field : 'lostScrapCount',
                    title : '遗失报废数量',
                },
                {
                    field : 'yesCount',
                    title : '相符数量',
                },{
                    field : 'noCount',
                    title : '不相符数量',
                },{
                    title : '未盘到数量',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-info btn-xs" style="height: 30px;line-height: 25px" href="javascript:void(0)" onclick="showNoInventory(\'' + row.inventoryId + '\',\'' + row.assetId +'\',\'' + row.noInventoryCount + '\')">'+"&nbsp&nbsp"+row.noInventoryCount+'&nbsp&nbsp</a>');
                        return actions.join('');
                    }
                }
                ,{
                    title: '操作',
                    align: 'left',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="showAll(\'' + row.inventoryId + '\',\'' + row.assetNo + '\',\'' + row.assetId + '\')"><i class="fa fa-edit"></i>查看</a> ');
                        return actions.join('');
                    }
            }]
        };
        $.table.init(options);
    });
    //选择公司树
    function selectCompanyTree() {
        var deptId = $.common.isEmpty($("#companyId").val()) ? "100" : $("#companyId").val();
        var url = ctx + "system/dept/selectCompanyTree/" + deptId;
        var options = {
            title: '选择部门',
            width: "380",
            url: url,
            callBack: doSubmitCompany
        };
        $.modal.openOptions(options);
    }
    function doSubmitCompany(index, layero){
        var tree = layero.find("iframe")[0].contentWindow.$._tree;
        if ($.tree.notAllowParents(tree)) {
            var body = layer.getChildFrame('body', index);
            $("#companyId").val(body.find('#treeId').val());
            $("#companyName").val(body.find('#treeName').val());
            layer.close(index);
        }
    }
    /*选择使用部门树*/
    var width=isNotPc?'95%':'380';
    function selectDeptTreeUse() {
        var deptId = $.common.isEmpty($("#deptId").val()) ? "100" : $("#deptId").val();
        var url = ctx + "system/dept/selectDeptTree/" + deptId;
        var options = {
            title: '选择部门',
            width:width,
            url: url,
            callBack: doSubmitUse
        };
        $.modal.openOptions(options);
    }
    function doSubmitUse(index, layero){
        var tree = layero.find("iframe")[0].contentWindow.$._tree;
        if ($.tree.notAllowParents(tree)) {
            var body = layer.getChildFrame('body', index);
            $("#deptId").val(body.find('#treeId').val());
            $("#deptName").val(body.find('#treeName').val());
            layer.close(index);
        }
        $("#useUser").empty();
        $.post(ctx +"system/user/getUserByDept",{deptId:$("#deptId").val()},function (data) {
            $.each(data,function (index,p) {
                $("#useUser").append('<option value="'+p.userId+'">'+p.userName+'</option>');
            })
        });
    }
    /*选择管理部门树*/
    function selectDeptTree() {
        var deptId = $.common.isEmpty($("#manageDept").val()) ? "100" : $("#manageDept").val();
        var url = ctx + "system/dept/selectDeptTree/" + deptId;
        var options = {
            title: '选择部门',
            width: width,
            url: url,
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }
    function doSubmit(index, layero){
        var tree = layero.find("iframe")[0].contentWindow.$._tree;
        if ($.tree.notAllowParents(tree)) {
            var body = layer.getChildFrame('body', index);
            $("#manageDept").val(body.find('#treeId').val());
            $("#manageDeptName").val(body.find('#treeName').val());
            layer.close(index);
        }
        $("#manageUser").empty();
        $.post(ctx +"system/user/getUserByDept",{deptId:$("#manageDept").val()},function (data) {
            $.each(data,function (index,p) {
                $("#manageUser").append('<option value="'+p.userId+'">'+p.userName+'</option>');
            })
        });
    }
    function showAll(inventoryId,assetNo,assetId) {
        $.modal.openTab("盘点信息",prefix + "/inventory/"+inventoryId+","+(assetNo=='null'?assetId:assetNo));
    }
    function showImg(id,imgCount) {
        if (parseInt(imgCount)>0){
            if(isNotPc) {
                $.modal.openFull('资产图片',ctx + "asset/assetDetail/showImg/"+id);
            }else {
                $.modal.open('资产图片', ctx + "asset/assetDetail/showImg/" + id);
            }
        }else{
            $.modal.alertWarning("没有图片");
        }
    }
    function showNoInventory(inventoryId,assetId,noInventoryCount) {
        if (noInventoryCount=='0') {
            $.modal.alert("暂无未盘到记录！");
        }else{
            $.modal.open('未盘到资产', prefix + "/noInventory/"+inventoryId+","+assetId);
        }
    }
</script>
</body>
</html>